As explained in OPC UA User Authentication (Client), a connection (OPC UA session) can be associated with a specified user identity. In OPC Data Client, the user identity is specified using the UserIdentity Property in the endpoint descriptor object (UAEndpointDescriptor Class) that is passed to OPC Data Client operations. If you like, you can use different user identities, and OPC Data Client will then create and maintain separate OPC UA sessions for them, one for every user identity.
In addition to the approach described above, OPC UA has a feature that allows the clients to change the identity of the user on an existing connection (OPC UA session), without having to close the session and re-open it. OPC Data Client supports this feature as well. Note that this feature is only available if the OPC UA server also supports it.
Changing the user identity on an existing session has some performance advantages over creating a separate session for a new user identity. It also allows the client and the server to keep the existing data change and event subscriptions, without having to re-establish them, resulting in smoother transition.
The dynamic user identity change is sometimes called "user switching".
The dynamic user identity change makes use of object alising. Basically, instead of using a specific constant user identity in the endpoint descriptor, you give it a name (an alias). The alias name remains the same, but the user identity value represented by the alias can be changed as you wish.
When OPC Data Client detects that the user identity represented by the alias has changed, it picks up the new user identity. If there is an open OPC UA session associated with the endpoint descriptor, OPC Data Client then attempts to switch the session to the new user identity.
If the user identity change succeeds (in the OPC UA server), the operations then proceed as normally, albeit with a new user identity, which means that the OPC UA session now possibly has different permissions. If the user identity change fails (for example, when the OPC UA server does not authenticate the newly required user), subsequent OPC UA operations using the same endpoint descriptor will return an error, and your subscriptions (event handlers or callbacks) will receive an error notification (and will stop receiving further notifications). You need to change the user identity back to the original identity, or to some other valid user identity, to resume the normal operations.
In order to use the dynamic user identity change, your code typically needs to perform the following steps: